home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / dskut / dump11.zip / DUMP.ASM next >
Assembly Source File  |  1985-12-18  |  14KB  |  318 lines

  1.         page    55,132
  2.         title   'DUMP --- Hex and ASCII Dump Filter'
  3. ; DUMP --- filter to transform the Standard Input stream into a
  4. ;          Hex and ASCII dump, which is written to the Standard Output.
  5. ;
  6. ; Version 1.0 Richard G. Markley  July 20, 1985
  7. ;   From Dr Dobbs Journal, November 1985
  8. ; Version 1.1 Ted Shapin, Dec. 18, 1985
  9. ;   Modified to also take a name on the command line
  10.  
  11. cr              equ     0dh             ;ASCII carriage return
  12. lf              equ     0ah             ;ASCII line feed
  13. space           equ     20h             ;ASCII space
  14. tab             equ     09h             ;ASCII tab
  15.  
  16. ;DOS 2.x predefined handles
  17.  
  18. Std_Input       equ     0               ;Standard Input device or file
  19. Std_Output      equ     1               ;Standard Output device or file
  20. Std_Err         equ     2               ;Standard Error device or file
  21.  
  22. ;DOS function numbers
  23.  
  24. Get_Version     equ     030h            ;get current DOS version
  25. Device_Input    equ     03fh            ;read from file or device
  26. Device_Output   equ     040h            ;write to file or device
  27. Exit            equ     04ch            ;exit with return code
  28.  
  29. code            segment para public 'CODE'
  30.  
  31.                 assume  cs:code,ds:code,es:code,ss:code
  32.  
  33.                 org     100h
  34.  
  35. dump            proc    far
  36.  
  37.                 jmp     start
  38.  
  39. ; data area
  40.  
  41. Column_Guide    db      11 dup  (' ')
  42.                 db      '0  1  2  3  4  5  6  7  8  9  '
  43.                 db      'A  B  C  D  E  F',cr,lf
  44. Col_Guide_Size  equ     $-Column_Guide
  45.  
  46. Data_String     db      3 dup (' ')
  47.  
  48. Byte_Counter    db      '000000  '
  49.  
  50. Hex_String      dw      25 dup (?)
  51.  
  52. ASCII_String    dw      8 dup (?)
  53.                 db      cr,lf
  54. String_Size     equ     $-Data_String
  55. Appx_String_Len equ     (LENGTH Hex_String)+(LENGTH ASCII_String)
  56.  
  57. New_Lines       db      cr,lf     ;one blank line
  58. New_Lines_Size  equ     $-New_Lines
  59.  
  60. Line_Count      db      ?               ;Count of lines per block
  61.  
  62. filen           db      40 dup(0) ; File name (paths OK)
  63. fileh           dw      0000H     ; File handle
  64.  
  65. ; error messages
  66. Pre_DOS_Error   db      cr,lf,'DUMP: DOS 2 or greater required',cr,lf
  67. Pre_DOS_Size    equ     $-Pre_DOS_Error
  68.  
  69. Input_Error     db      cr,lf,'DUMP: input device error',cr,lf
  70. Input_Size      equ     $-Input_Error
  71.  
  72. Empty_Error     db      cr,lf,'DUMP: missing input error',cr,lf
  73. Empty_Size      equ     $-Empty_Error
  74.  
  75. Output_Error    db      cr,lf,'DUMP: output device error',cr,lf
  76. Output_Size     equ     $-Output_Error
  77.  
  78. Disk_Full_Error db      cr,lf,'DUMP: disk is full',cr,lf
  79. Disk_Full_Size  equ     $-Disk_Full_Error
  80.  
  81. Start:          mov     ah,Get_Version  ;check version of DOS
  82.                 int     21h
  83.  
  84.                 or      al,al           ;is it DOS v. 2.0 or higher?
  85.                 jnz     Prepare         ;yes, proceed
  86.                 jmp     Error_1         ;no, output error message
  87.  
  88. Prepare:                                ;prepare for processing
  89.                 cld
  90.                 mov     bp,-1           ;prevent output if no input
  91.                 call    Findname        ;see if a name on command line
  92.                 call    Input           ;perform input of data
  93.  
  94. Main_Loop:                              ;output heading'
  95.                 mov     cx,Col_Guide_size
  96.                 mov     dx,offset Column_Guide
  97.                 call    Output
  98.                                         ;now dump a block
  99.                 mov     Line_Count,8    ;number of lines per block
  100.                 jmp     Do_Block
  101. Output_Lines:                           ;send 1 blank lines
  102.                 mov     cx,New_lines_Size
  103.                 mov     dx,offset New_Lines
  104.                 call    Output
  105.                 jmp     Main_Loop
  106.  
  107. Do_Block:                               ;initialize part of data
  108.                                         ;template with spaces
  109.                 mov     ax,2020h
  110.                 mov     cx,Appx_String_Len
  111.                 mov     di,offset Hex_String
  112.                 rep stosw
  113.                                         ;initialize pointers
  114.                                         ;and convert data
  115.                 mov     bx,offset Hex_String
  116.                 mov     dx,size ASCII_String
  117.                 mov     di,offset ASCII_String
  118.                 jmp     Do_Line
  119.  
  120. Output_Data:    mov     cx,String_Size  ;write a line to Std Output
  121.                 mov     dx,offset Data_String
  122.                 call    Output
  123.                                         ;set pointer to sixteen's
  124.                                         ;place of byte counter
  125.                 mov     di,offset Byte_Counter+4
  126.                                         ;number of places in byte
  127.                 mov     cx,5            ;counter minus one
  128.  
  129. Adjust_Counter:                         ;increment input offset counter
  130.                 inc     byte ptr [di]   ;incr current number place value
  131.                 mov     al,[di]
  132.                 cmp     al,'9'          ;is it 9 or less?
  133.                 jbe     Check_line_Cnt  ;yes, check no. of lines output
  134.                 cmp     al,'A'          ;no is it larger than A?
  135.                 ja      check_For_F     ;yes, jump
  136.                 mov     byte ptr [di],'A'
  137.                 jmp     short Check_Line_Cnt
  138.  
  139. Check_For_F:    cmp     al,'F'          ;is it 'F' or less?
  140.                 jbe     Check_Line_Cnt  ;yes, check number of lines output
  141.                 mov     byte ptr [di],'0' ;no, make the digit '0'
  142.                 dec     di              ;move ptr to next higher place
  143.                 Loop    Adjust_Counter  ;carry into next higher digit
  144.  
  145.                                         ;check number of lines output
  146. Check_line_Cnt: dec     Line_Count      ;has block been output?
  147.                 jne     do_Block        ;no, output another line
  148.                 jmp     Output_Lines    ;yes, output blank
  149.  
  150.                                         ;place ASCII equivalent of
  151.                                         ;byte in string
  152. Do_Line:        mov     al,[si]         ;get byte from buffer
  153.                 mov     ch,al           ;keep copy
  154.                 cmp     al,' '          ;control code?
  155.                 jb      Not_Printable   ;yes, jump
  156.                 cmp     al,'~'          ;no, is char a tilde or less?
  157.                 jbe     Printable       ;yes, use it
  158.  
  159. Not_Printable:  mov     al,'.'          ;substitute '.' if not printable
  160.  
  161. Printable:      stosb                   ;store into ASCII section of output
  162.                                         ;place hex equivalent of byte
  163.                                         ;in output string
  164.                 mov     ah,2            ;number of nibbles in a byte
  165.                 xchg    di,bx           ;get hex section offset
  166. Swap_Nibbles:   mov     cl,4            ;size of nibble in bits
  167.                 rol     ch,cl           ;exchange nibbles
  168.                 mov     al,ch           ;save copy
  169.                 and     al,0fh          ;mask off high 4 bits
  170.                 add     al,'0'          ;convert to ASCII char.
  171.                 cmp     al,'9'          ;is it '0-9'?
  172.                 jbe     Place_Digit     ;yes, store result
  173.                 add     al,7            ;put it into range 'A-F'
  174.  
  175. Place_Digit:    stosb                   ;store into hex section of output
  176.                 dec     ah              ;any more nibbles?
  177.                 jnz     Swap_Nibbles    ;yes, convert again
  178.  
  179.                                         ;reposition pointers
  180.                 xchg    di,bx           ;get ASCII section offset
  181.                 inc     bx              ;skip space in hex section
  182.                 inc     si              ;move input pointer
  183.  
  184.                                         ;input data when buffer empty
  185.                 dec     bp              ;buffer used up yet?
  186.                 jnz     Check_Item_Cnt  ;no, check item count
  187.                 call    input
  188.  
  189.                                         ;check number of items stored
  190. Check_Item_Cnt: dec     dx              ;store more d